﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.Linq;
using System.Text;
using WA.Core.DomainModel;
using WA.Core.DaoInterfaces;
using WA.Data;

namespace WA.Data
{
    /// <summary>
    /// Simple class to implement DataContext singleton.
    /// </summary>
    public sealed class ObjectContextManager
    {
        private WAObjectContext db;

        #region Thread-safe, lazy Singleton

        /// <summary>
        /// This is a thread-safe, lazy singleton.  
        /// See http://www.yoda.arachsys.com/csharp/singleton.html
        /// for more details about its implementation.
        /// </summary>
        public static ObjectContextManager Instance
        {
            get
            {
                return Nested.objectContextManager;
            }
        }

        /// <summary>
        /// Initializes BoPDataContext.
        /// </summary>
        private ObjectContextManager()
        {
            InitDB();
        }

        /// <summary>
        /// Assists with ensuring thread-safe, lazy singleton
        /// </summary>
        private class Nested
        {
            static Nested() { }
            internal static readonly ObjectContextManager objectContextManager =
                new ObjectContextManager();
        }

        #endregion

        private void InitDB()
        {

            db = new WAObjectContext();

        }

        public WAObjectContext GetContext()
        {
            return db;

        }

    }


}



